﻿namespace SageKing.Core.Contracts;

/// <summary>
/// Filter item definition
/// </summary>
public class SageKingFilter
{
    /// <summary>
    /// The display text of the filter item
    /// </summary>
    public string Text { get; set; }

    /// <summary>
    /// The value of the filter item
    /// </summary>
    public object Value { get; set; }

    /// <summary>
    /// Whether the filter item is selected
    /// </summary>
    public bool Selected { get; set; }

    /// <summary>
    /// The compare operators supported by the filter item
    /// </summary>
    public SageKingFilterCompareOperator FilterCompareOperator { get; internal set; }

    /// <summary>
    /// The condition of the filter item
    /// </summary>
    public SageKingFilterCondition FilterCondition { get; internal set; }

    internal void SelectValue(bool selected)
    {
        this.Selected = selected;
    }

    public SageKingFilter()
    {
    } 
    public SageKingFilter(string text, object value, bool selected, SageKingFilterCompareOperator filterCompareOperator, SageKingFilterCondition filterCondition)
    {
        this.Text = text;
        this.Value = value;
        this.Selected = selected;
        this.FilterCompareOperator = filterCompareOperator;
        this.FilterCondition = filterCondition;
    }
}

public class SageKingFilter<TValue> : SageKingFilter
{
    public SageKingFilter()
    {
    }
     
    public SageKingFilter(string text, object value, bool selected, SageKingFilterCompareOperator filterCompareOperator, SageKingFilterCondition filterCondition) : base(text, value, selected, filterCompareOperator, filterCondition)
    {
    }

    new public TValue Value { get => (TValue)(base.Value ?? default(TValue)); set => base.Value = value; }
}
